package com.woniuxy.stage3demo.service.kang.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.stage3demo.bean.kang.CustomerBean;
import com.woniuxy.stage3demo.mapper.kang.CustomerMapper;
import com.woniuxy.stage3demo.pageHelper.PageRequest;
import com.woniuxy.stage3demo.service.kang.ICustomerService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

@Transactional(readOnly = true)
@Service
public class CustomerServiceImpl implements ICustomerService {

    @Resource
    private CustomerMapper customerMapper;

    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    @Override
    public int addCustomer(CustomerBean customerBean) {
        return customerMapper.addCustomer(customerBean);
    }

    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    @Override
    public int deleteCustomer(Long id) {
        return customerMapper.deleteCustomer(id);
    }

    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    @Override
    public int updateCustomer(CustomerBean customerBean) {
        return customerMapper.updateCustomer(customerBean);
    }

    @Override
    public PageInfo<CustomerBean> findLimit(PageRequest pageRequest) {
        return PageHelper.startPage(pageRequest.getPageNum(),pageRequest.getLimit()).doSelectPageInfo(()->customerMapper.findLimit(pageRequest));
    }


}
